let db = require('../db/index')

exports.get = (req,res) =>{//通过姓名查询数据
    var sql = "select * from users where name like '%' ?"
    db.query(sql,[req.query.name],(err,data)=>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })
}

exports.del = (req,res) =>{//通过姓名删除数据
    var sql = 'delete from users where name = ?'
    db.query(sql,[req.query.name],(err,data) =>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })

}

exports.add = (req,res)=>{
    var sql = 'insert into users (name,password,sex,email,id) values (?,?,?,?,?)'
    db.query(sql, [req.query.name,req.query.password,req.query.sex,req.query.email,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}

exports.update = (req,res)=>{
    var sql = 'update users set name = ?, password = ?,sex = ?,email = ? where id = ?'
    db.query(sql, [req.query.name,req.query.password,req.query.sex,req.query.email,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}